import {saveWebVisit} from '../../bomb/db.visit.js'

//不支持https跨域，否则403
const pcOnlineUrl = "https://whois.pconline.com.cn/ipJson.jsp"

$(document).ready(() => {
    getIpLocationByPcOnline(res => {
        saveWebVisit(res)
    })
});

/**
 * 获取ip地址信息
 * @param callback 获取成功后回调方法
 */
function getIpLocationByPcOnline(callback) {
    $.ajax({
        url: pcOnlineUrl,
        dataType: 'jsonp',
        success: function (res) {
            console.log(res);
            callback({
                address: res.addr,
                city: res.city,
                ip: res.ip,
            })
        },
        // Ajax接口出现错误时执行下述代码
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            /*弹出jqXHR对象的信息*/
            console.error(XMLHttpRequest, textStatus, errorThrown);
            callback({
                error: textStatus,
                address: "",
                city: "",
                ip: "",
            })
        }
    })
}


